<?php

global $footer, $data;

class Tools extends CI_Controller {

    public function __construct() {
        parent::__construct();
        global $footer, $data;
        if ($this->session->userdata('lang') == 'spanish') {
            $data['herramienta'] = $this->ciempies_model->lista_herramientas('_ES');
            $this->lang->load('about', 'spanish');
            $footer = "footer";
            $data['icon_lang'] = "en.jpg";
        } else {
            $this->lang->load('about', 'english');
            $data['herramienta'] = $this->ciempies_model->lista_herramientas('_EN');
            $footer = "footer_en";
            $data['icon_lang'] = "es.jpg";
        }
        $this->cargarIdioma();
        $data['place'] = "tools";
        $this->registrar_visita($data['place']);
    }

    #registra la palabra procesada
    public function ruh() {
        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
        $this->form_validation->set_rules('palabra', 'palabra procesada', 'trim|required|xss_clean');
        if ($this->form_validation->run()) {
            $palabra = urldecode($this->input->post('palabra'));
            $uh_herramienta = urldecode($this->input->post('herramienta'));
            $fecha = date('Y-m-j');
            $hora = date('H:i:s');
            $this->ciempies_model->registrar_palabra_proc($fecha, $hora, $palabra, $uh_herramienta);
        }
        redirect(base_url());
    }

    public function index() {
        global $footer, $data;

        $this->load->view('template/front_end/header', $data);
        $this->load->view('front_end/tools_main');
        $this->load->view('front_end/tools_news');
        $this->load->view('template/front_end/' . $footer);
    }

    public function solve($id) {
        global $footer, $data;

        if ($this->session->userdata('lang') == 'spanish') {
            $data['tool'] = $this->ciempies_model->full_herramienta($id, '_ES');
            $footer = "footer";
        } else {
            $data['tool'] = $this->ciempies_model->full_herramienta($id, '_EN');
            $footer = "footer_en";
        }

        $this->load->view('template/front_end/header', $data);
        $this->load->view('online_tools/cuerpo_funcion');
        $this->load->view('front_end/tools_news');
        $this->load->view('template/front_end/' . $footer);
    }

    public function cargarIdioma() {
        global $data;
        /*  traduccion del menú */
        $data['headerTituloNotros'] = $this->lang->line('headerTituloNotros');
        $data['headerTituloDescarg'] = $this->lang->line('headerTituloDescarg');
        $data['headerTituloHerram'] = $this->lang->line('headerTituloHerram');
        $data['headerTituloDocu'] = $this->lang->line('headerTituloDocu');
        $data['headerTituloCol'] = $this->lang->line('headerTituloCol');
        $data['headerTituloNoticias'] = $this->lang->line('headerTituloNoticias');
        $data['headerTituloContcato'] = $this->lang->line('headerTituloContcato');
        $data['toolsNewsTitle'] = $this->lang->line('toolsNewsTitle');
        $data['toolsNewsCont'] = $this->lang->line('toolsNewsCont');


        /* tools */
        $data['docNewsTitle'] = $this->lang->line('docNewsTitle');
        $data['docNewsCont'] = $this->lang->line('docNewsCont');
        $data['tools_main_title'] = $this->lang->line('tools_main_title');
    }

    public function lenChg() {
        global $data;
        if ($this->session->userdata('lang') == 'spanish') {
            $this->session->set_userdata('lang', 'english');
        } else {
            $this->session->set_userdata('lang', 'spanish');
        }
        redirect(base_url() . $data['place']);
    }

    public function registrar_visita($place) {
        $v_sitio = "ciempiess.org/$place";
        $v_date = date('Y-m-j H:i:s');
        $v_ip = $this->input->ip_address();
        $this->ciempies_model->registrar_visita($v_sitio, $v_date, $v_ip);
    }

}
